package com.awanp3.nimbus.wms.fg.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.awanp3.nimbus.common.idempotent.annotation.RepeatSubmit;
import com.awanp3.nimbus.common.log.annotation.Log;
import com.awanp3.nimbus.common.web.core.BaseController;
import com.awanp3.nimbus.common.mybatis.core.page.PageQuery;
import com.awanp3.nimbus.common.core.domain.R;
import com.awanp3.nimbus.common.core.validate.AddGroup;
import com.awanp3.nimbus.common.core.validate.EditGroup;
import com.awanp3.nimbus.common.log.enums.BusinessType;
import com.awanp3.nimbus.common.excel.utils.ExcelUtil;
import com.awanp3.nimbus.wms.fg.domain.vo.WmsCountingOrderInfoVo;
import com.awanp3.nimbus.wms.fg.domain.bo.WmsCountingOrderInfoBo;
import com.awanp3.nimbus.wms.fg.service.IWmsCountingOrderInfoService;
import com.awanp3.nimbus.common.mybatis.core.page.TableDataInfo;

/**
 * 盘点单
 * 前端访问路由地址为:/wms/countingOrderInfo
 *
 * @author 20014170
 * @date 2025-09-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/countingOrderInfo")
public class WmsCountingOrderInfoController extends BaseController {

    private final IWmsCountingOrderInfoService wmsCountingOrderInfoService;

    /**
     * 查询盘点单分页列表
     */
    @SaCheckPermission("wms:countingOrderInfo:list")
    @GetMapping("/page")
    public TableDataInfo<WmsCountingOrderInfoVo> page(WmsCountingOrderInfoBo bo, PageQuery pageQuery) {
        return wmsCountingOrderInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询盘点单列表
     */
    @SaCheckPermission("wms:countingOrderInfo:list")
    @GetMapping("/list")
    public R<List<WmsCountingOrderInfoVo>> list(WmsCountingOrderInfoBo bo) {
        List<WmsCountingOrderInfoVo> list = wmsCountingOrderInfoService.queryList(bo);
        return R.ok(list);
    }


    /**
     * 导出盘点单列表
     */
    @SaCheckPermission("wms:countingOrderInfo:export")
    @Log(title = "盘点单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WmsCountingOrderInfoBo bo, HttpServletResponse response) {
        List<WmsCountingOrderInfoVo> list = wmsCountingOrderInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "盘点单", WmsCountingOrderInfoVo.class, response);
    }

    /**
     * 获取盘点单详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("wms:countingOrderInfo:query")
    @GetMapping("/{id}")
    public R<WmsCountingOrderInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(wmsCountingOrderInfoService.queryById(id));
    }

    /**
     * 新增盘点单
     */
    @SaCheckPermission("wms:countingOrderInfo:add")
    @Log(title = "盘点单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsCountingOrderInfoBo bo) {
        return toAjax(wmsCountingOrderInfoService.insertByBo(bo));
    }

    /**
     * 修改盘点单
     */
    @SaCheckPermission("wms:countingOrderInfo:edit")
    @Log(title = "盘点单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsCountingOrderInfoBo bo) {
        return toAjax(wmsCountingOrderInfoService.updateByBo(bo));
    }

    /**
     * 删除盘点单
     *
     * @param ids 主键串
     */
    @SaCheckPermission("wms:countingOrderInfo:remove")
    @Log(title = "盘点单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(wmsCountingOrderInfoService.deleteWithValidByIds(List.of(ids), true));
    }
}
